<?php

function controller_profil($config) {
    if (isset($_SESSION['logged'])){
		if (isset($_POST['ubah'])){
			$uname = strtolower($_POST['uname']);
			$pass = strtolower($_POST['pass']);
			$nohp = strtolower($_POST['nohp']);
			$email = strtolower($_POST['email']);
			$twitter = strtolower($_POST['tw']);
			$db =  new db($config);
			$result = $db->query("UPDATE mn_crew SET username='$uname', no_hape='$nohp', email='$email', twitter='$twitter' WHERE idCrew = '".$_SESSION['logged']['id']."'");
			if ($pass=='') {}else{
				$result = $db->query("UPDATE mn_crew SET password='".md5($pass)."' WHERE idCrew = '".$_SESSION['logged']['id']."'");
			}
			$_SESSION['succ'] = "Profil berhasil dirubah";
			$_SESSION['logged']['uname'] = $uname;
			$_SESSION['logged']['no_hape'] = $nohp;
			$_SESSION['logged']['email'] = $email;
			$_SESSION['logged']['twitter'] = $twitter;
			header('Location: '.$config['home_url'].'profil');
		}else
			view_profil($config,array());
	} else
		header('Location: '.$config['home_url']);
}
